package com.app.controller.supermarket;
import com.app.mapper.supermarket.MktPersonMapper;
import com.app.mapper.supermarket.SkillMapper;
import com.app.mapper.supermarket.SkillSonMapper;
import com.app.model.supermarket.MktPersonModel;
import com.app.model.supermarket.SkillSonModel;
import com.app.service.supermarket.MktPersonService;
import com.app.service.supermarket.SkillService;
import com.app.service.supermarket.SkillSonService;
import com.app.util.BizException;
import com.app.util.Result;
import com.app.util.TokenUtils;
import io.swagger.annotations.ApiOperation;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description: 技能子标签控制层
 * @Date: 2022/11/13 17:06
 */
@RestController
@RequestMapping("api/skillSon")
public class SkillSonController {
    @Autowired
    private SkillSonService skillSonService;
    @Autowired
    private MktPersonService mktPersonService;
    @Autowired
    private SkillService skillService;

    @ApiOperation("获取技能标签列表")
    @RequestMapping(value = "/getSkill", method = RequestMethod.GET)
    public Result<Object> getSkillList(HttpServletRequest request, Integer sid) {
        String token = request.getHeader("token");
        if(token==null)
        {
            return Result.error(405,"token不存在");
        }
        String mobile = TokenUtils.verify(token);
        MktPersonModel mktPerson = mktPersonService.getModelByMobile(mobile);
        if(mktPerson==null)
        {
            return Result.error(405,"用户不存在");
        }
        List<SkillSonModel> model = skillSonService.getSkillsBySid(sid);
        return Result.success(model);
    }

    @ApiOperation(value = "新增")
    @GetMapping(value = "/addSkillSon")
    public Result<Object> addSkillSon(HttpServletRequest request,
                              @RequestParam("skills") String skills
    ) {
        String token = request.getHeader("token");
        if(token==null)
        {
            return Result.error(405,"token不存在");
        }
        String mobile = TokenUtils.verify(token);
        MktPersonModel mktPerson = mktPersonService.getModelByMobile(mobile);
        if(mktPerson==null)
        {
            return Result.error(405,"用户不存在");
        }
        mktPerson.setSkills(skills);
        mktPerson.setId(mktPerson.getId());
        mktPersonService.update(mktPerson);

        return Result.success("操作成功");
    }
    @ApiOperation("修改技能标签")
    @RequestMapping(value = "/updateSkillSon", method = RequestMethod.GET)
    String updateSkillSon(HttpServletRequest request) {
        SkillSonModel skillSon1 = new SkillSonModel();
        skillSon1.setMid(0);
        skillSonService.update(skillSon1);
        JSONObject object = new JSONObject();
        String sonSort = request.getParameter("sonSort");
        String test = request.getParameter("test");
        object.put("code", 200);
        object.put("message", "成功");
        return object.toString();
    }
}
